package com.lyhlmj.oop_client.Frames.LoginAndRegister.LoginFrame;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.File;

public class LoginBackgroundPanel extends JPanel {
    private Image image;

    //  得到Frame的大小
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = (int)(0.9 * screenSize.getWidth());
    int height = (int)(0.9 * screenSize.getHeight());

    public LoginBackgroundPanel() {
        try {
            this.setImage(ImageIO.read(new File("data/oop登录界面背景.jpg")));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void setImage(Image image) {
        this.image = image;
        this.repaint();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        //  设置MainFrame背景
        //  读取图片文件
        if (image != null) {
            g.drawImage(image, 0, 0, width, height, null);
        }

        g.setColor(new Color(255, 255, 255, 20));
        g.fillRect(0, 0, width, height);
    }
}
